#!/bin/bash

# 高级MCP功能测试脚本

PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
BINARY="$PROJECT_ROOT/bin/k8s-mcp-server"

echo "K8s MCP 高级功能测试"
echo "项目路径: $PROJECT_ROOT"
echo
export KUBECONFIG="$PROJECT_ROOT/config/kube-config"

# 颜色定义
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo -e "${BLUE}测试 1: 获取特定命名空间的pods${NC}"
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "k8s_get_pods", "arguments": {"namespace": "kube-system", "output_format": "wide"}}}' | "$BINARY" | head -10
echo
echo "==============================="

echo -e "${BLUE}测试 2: 获取deployments${NC}"
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "k8s_get_deployments", "arguments": {"namespace": "default"}}}' | "$BINARY" | head -10
echo
echo "==============================="

echo -e "${BLUE}测试 3: 获取services${NC}"
echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "k8s_get_services", "arguments": {"namespace": "default"}}}' | "$BINARY" | head -10
echo
echo "==============================="

echo -e "${BLUE}测试 4: 执行自定义kubectl命令 - 获取Pod资源使用情况${NC}"
echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "k8s_execute_kubectl", "arguments": {"command": "top pods --no-headers"}}}' | "$BINARY" | head -10
echo
echo "==============================="

echo -e "${BLUE}测试 5: 描述特定资源${NC}"
echo '{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "k8s_describe_resource", "arguments": {"resource_type": "pod", "resource_name": "dasapp-pg-0", "namespace": "default"}}}' | "$BINARY" | head -20
echo
echo "==============================="

echo -e "${BLUE}测试 6: 获取Pod日志（获取最近10行）${NC}"
echo '{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "k8s_get_pod_logs", "arguments": {"pod_name": "dasapp-pg-0", "namespace": "default", "tail_lines": "10"}}}' | "$BINARY" | head -15
echo
echo "==============================="

echo -e "${GREEN}所有高级MCP工具测试完成！${NC}"
echo -e "${YELLOW}注意: 某些命令可能因为权限或资源不存在而失败，这是正常的。${NC}" 